package com.xiaodimall.backsys.controller;

import com.xiaodimall.backsys.service.AdminService;
import com.xiaodimall.common.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author wyc
 * @description
 * @ClassName AdminController
 * @date 2022/11/25 9:54
 */
@Controller
public class AdminController {

    @Resource
    AdminService adminService;


    /**
     * 跳转后天首页
     * @return admin/index
     */
    @GetMapping("admin/index")
    public String toLogin(){
        return "admin/index";
    }


    @GetMapping("/toAdminLogin")
    public String toAdminLogin(){
        return "admin/login";
    }


    /**
     * 后台登录功能
     * @author WYC
     * @param userName
     * @param password
     * @param verifyCode
     * @param session
     * @return: 成功返回首页
     * @date: 2022/11/25 10:31
     */
    @PostMapping("/adminLogin")
    public String login(@RequestParam("userName") String userName,
                        @RequestParam("password") String password,
                        @RequestParam("verifyCode") String verifyCode,
                        HttpSession session) {
        return adminService.doAdminLogin(userName,password,verifyCode,session);
    }

    @GetMapping("/loginOut")
    public String loginOut(HttpSession session){
        session.removeAttribute(Constants.MALL_USER_SESSION_KEY);
        return "mall/index";
    }
}
